package com.huitone.gddw.controller.monitoring;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.ResponseBody;



import com.huitone.gddw.dao.entity.MainItem;

import com.huitone.gddw.dao.entity.ReturnedValue;


import com.huitone.gddw.service.MainItemService;
import com.huitone.gddw.utils.MonitoringResult;

/**
 * 主机监控Controller
 * @author lipengfei
 *
 */
@Controller
@RequestMapping(value="mainmon")
public class MainMonitoringController {
	private final static Logger LOGGER = Logger.getLogger(MainMonitoringController.class);
	
	@Resource
	private MainItemService mainService;
	
	@ResponseBody
	@RequestMapping(value="/selectMain",method=RequestMethod.POST)
	public MonitoringResult<List<MainItem>> showMainItem(ReturnedValue value){
		MonitoringResult<List<MainItem>> result = 
				mainService.loadMainItem(value);
		LOGGER.info("显示主机总监控数据完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/addIndex",method=RequestMethod.POST)
	public MonitoringResult<Map<String, Object>> addIndex(){
		MonitoringResult<Map<String,Object>> result = mainService.addIndex();
		System.out.println(result.getMsg());
		
		LOGGER.info("添加主机名称完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/showIndex",method=RequestMethod.POST)
	public MonitoringResult<Map<String,Object>> showIndex(ReturnedValue value){
		MonitoringResult<Map<String,Object>> result = 
				mainService.showIndex(value);
		LOGGER.info("获得指标数据完成");
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/saveIndex",method=RequestMethod.POST)
	public MonitoringResult<MainItem> save(ReturnedValue value){
		MonitoringResult<MainItem> result = 
				mainService.save(value);
		LOGGER.info("保存指标数据完成");
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/updataIndex",method=RequestMethod.POST)
	public MonitoringResult<Map<String,Object>> updata(ReturnedValue returnedValue){
		MonitoringResult<Map<String,Object>> result = 
				mainService.updata(returnedValue);
		LOGGER.info("获取更新指标数据完成");
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/updataSave",method=RequestMethod.POST)
	public MonitoringResult<MainItem> updataSave(ReturnedValue value){
		MonitoringResult<MainItem> result = 
				mainService.updataSave(value);
		LOGGER.info("更新指标数据完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/showExe",method=RequestMethod.POST)
	public MonitoringResult<Map<String,Object>> showExe(ReturnedValue value){
		MonitoringResult<Map<String,Object>> result = 
				mainService.showExe(value);
		LOGGER.info("异常信息获取完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/createExcle",method=RequestMethod.POST)
	public MonitoringResult<MainItem> createExcel(HttpServletResponse response,ReturnedValue value){
		MonitoringResult<MainItem> result = mainService.createExcel(response,value);
		System.out.println(result.getMsg());
		LOGGER.info("导出表格完成");
		return result;
	}
}
